<?php 
class Rooms extends E_Entity 
{
	public   $table =array(
					"id" =>"id",
					"version" =>"version",
					"siteid" =>"siteid",
					"userid" =>"userid",
					"name" =>"name",
					"sort" =>"sort", 
	 				"modsort" =>"modsort", 
					"sign" =>"sign",
					"status" =>"status",
					"ctime" =>"ctime",
					"mtime" =>"mtime"
					);
	public function getTableName()
	{
		return "micro_room";
	}
	public function getJoinMap()
	{
		$map = array("mapGroup" =>array("Entity"=>"Groups","Method"=>"getById", "param"=>"groupid"),
					 "mapUser" =>array("Entity"=>"Users","Method"=>"getById", "param"=>"userid")
			);
		return $map;
	}
	public static function insertEntity($row)
	{	
		$entity = new self();
	 	return $entity->createEntityForRow($row);
	}
	public static function getById($id)
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where  {$entity->table['id']} = :id ";
		return $entity->getEntityByIndexKey($sql, $id, array("id"=>$id));
	}
	public static function getByUserid($userid)
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where  {$entity->table['userid']} = :userid";
		return $entity->getEntityByIndexKey($sql, $id, array("userid"=>$userid));
	}
	public static function getNum($siteid)
	{
		$entity = new self();
		$db = $entity->getDbHandle();
		
		$sql =  "select count(1) as num  from {$entity->getTableName()} where {$entity->table['siteid']} = '$siteid'";
		$row = $db->fetch($sql);
		return $row['num'];
	}
	public static function getBySiteId($siteid)
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where   {$entity->table['siteid']} = '$siteid' order by id ";
		return $entity->getEntityByIndexKey($sql);
	}
	public static function getListBySiteId($siteid)
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where   {$entity->table['siteid']} = '$siteid' order by id ";
		return $entity->birthEntity($sql);
	}
}
?>